package edu.ncst.baseweb.controller.borrow;

import cn.wintersun.basecommon.common.Result;
import edu.ncst.baseweb.dao.BorrowRecord;
import edu.ncst.baseweb.service.intrer.borrow.BorManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 设备管理页面
 */
@RestController
@RequestMapping("/admin/bormanage/bromanage")
@PreAuthorize("hasAuthority('5')")
//借用管理
public class BorManageController {
    @Autowired
    private BorManageService borManageService;


    //需要审核的借用记录列表
    @RequestMapping(value = "list",method = RequestMethod.POST)
    public Result<IPage<BorrowRecord>> list(@RequestBody BorrowRecord borrowrecord){

        return  borManageService.list(borrowrecord);
    }
    //借用设备的审批
    @RequestMapping(value = "approve",method = RequestMethod.POST)
    public Result<Object> approve(@RequestBody BorrowRecord borrowrecord){
        try {
            return  borManageService.approve(borrowrecord);
        } catch (Exception e) {
            //抛出异常
            return Result.failure(500, e.getMessage());
        }
    }
}
